<? 
	include('base.php');
	User::protect();
	include_class('releases');
	include_class('m2');
	include_class('release_tracks');
	$section='releases';
	// in case we need it
	$page_title = 'Download Track';

	$rt = ReleaseTrack::get($_GET['id']);
	
if (!db::isError($rt)) {

	$r = $rt->getReleaseObject();
	$res = $rt->isValidAudioFile();
	if (!db::isError($res)) {
		$filesize = $rt->getAudioFileSize();
		
		header("Content-Type: application/mp3");
		header("Content-Disposition: attachment; filename=" . $rt->getAudioFile());
		header("Content-Length: " . $filesize);

		readfile(AUDIO_DIRECTORY . '/' . $rt->getAudioFile()); 
		exit();
	
	} else { ?>

		<? include('layout/header.php'); ?>
		
		<div id="breadcrumb">
			<a href="index.php">Audition &#62;</a>
			<a href="<?= AUDITION_WEB_DIRECTORY?>/releases.php">Releases &#62;</a>
			<a href="<?= AUDITION_WEB_DIRECTORY?>/release_edit.php?id=<?=$r->getID()?>">View/Edit Release &#62;</a>
			<a href="<?= AUDITION_WEB_DIRECTORY?>/release_track_edit.php?id=<?=$rt->getID()?>">View/Edit Track &#62;</a>
			Download Audio
		</div>
		
		<?
		
		$output->outputDialog('Return to Release Track','release_track_edit.php?id=' . $rt->getID());
	
		 include('layout/footer.php'); ?>

	<? }
	
} else { ?>

	<? include('layout/header.php'); ?>
	
	<div id="breadcrumb">
		<a href="<?= AUDITION_WEB_DIRECTORY?>/index.php">Audition &#62;</a>
		<a href="<?= AUDITION_WEB_DIRECTORY?>/releases.php">Releases &#62;</a>
		Invalid Entry
	</div>
	
	<?
	$rt->outputDialog('Return to Releases', AUDITION_WEB_DIRECTORY .'/releases.php');

	include('layout/footer.php');

} ?>


